Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Core java - Interview Questions and Answers for 'Ust global' - 3 question(s) found - Order By Newest | ||||
Very frequently asked. Among first few questions in almost all interviews. Among Top 5 frequently asked questions. Frequently asked in Indian service companies (HCL,TCS,Infosys,Capgemini etc based on multiple feedback ) and Epam Systems | ||||
| ||||
Ans. "equals" is the method of object class which is supposed to be overridden to check object equality, whereas "==" operator evaluate to see if the object handlers on the left and right are pointing to the same object in memory. x.equals(y) means the references x and y are holding objects that are equal. x==y means that the references x and y have same object. Sample code: String x = new String("str"); String y = new String("str"); System.out.println(x == y); // prints false System.out.println(x.equals(y)); // prints true | ||||
Sample Code for equals | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string comparison   string   object class   ==   equals   object equality  operator   == vs equals   equals vs == Asked in 294 Companies basic   frequent | ||||
Try 6 Question(s) Test | ||||
Related Questions | ||||
What is the difference between = and == in Java ? | ||||
How is == operator different for objects and primitive types ? | ||||
What will be the output of following code Integer x = 1; Integer y = 2; System.out.println(x == y); What if you change 1 to "1" and Integer to String? | ||||
Very frequently asked. Favorite question in Walk in Drive of many Indian service companies. | ||||
| ||||
Ans. They are different the way their elements are stored in memory. TreeMap stores the Keys in order whereas HashMap stores the key value pairs randomly. | ||||
Sample Code for treemap Sample Code for hashmap | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   map   treemap   hashmap   treemap vs hashmap Asked in 31 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
Related Questions | ||||
What is comparator interface used for ? | ||||
Which of the following collections stores its elements in insertion Order ? a. HashMap b. TreeMap c. LinkedHashMap d. LinkedMap | ||||
Which are the sorted collections ? | ||||
Which of the following collection maintain its elements in Natural Sorted order ? | ||||
How can we reverse the order in the TreeMap ? | ||||
TreeMap orders the elements on which field ? | ||||
How TreeMap orders the elements if the Key is a String ? | ||||
Can we add heterogeneous elements into TreeMap ? | ||||
Will it create any problem if We add elements with key as user defined object into the TreeMap ? | ||||
| ||||
Ans. Now the reference points to a new object in memory. If that was the only reference for the previous object , it will be marked for garbage collection. Foe example - Object obj = new Object(); obj = new Object(); object created in first line will be eligible for garbage collection after line 2 as it looses all it's handlers. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  references  objects  garbage collection Asked in 1 Companies | ||||
Related Questions | ||||
What are the common uses of "this" keyword in java ? | ||||
What are strong, soft, weak and phantom references in Java ? | ||||
When we say final x = 10, is the reference final or the value ? | ||||
Difference between a Pointer and a Reference ? | ||||
How are values passed in Java ? By value or reference ? | ||||
If a method definition has been specified in Class , its Base Class , and the interface which the class is implementing, Which definition will be picked if we try to access it using Interface Reference and Class object ? | ||||
If a method definition has been specified in the Base Class and the interface which the class is implementing, Which definition will be picked if we try to access it using Interface Reference and Class object ? | ||||
Can we access Interface static method using Interface references ? | ||||
Why is null == null returns true ? | ||||
Can we have foreign key reference to a non primary key column ? | ||||